package pers.jing.android.helper

import androidhelper.composeapp.generated.resources.Res
import androidhelper.composeapp.generated.resources.app_name
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application
import org.jetbrains.compose.resources.stringResource
import org.slf4j.LoggerFactory
import pers.jing.android.helper.model.UICloseSate
import java.io.File

fun main(args:Array<String>?) = application {
    var closeState by remember {
        mutableStateOf<UICloseSate>(UICloseSate.Idle)
    }
    var paramConfig by remember {
        mutableStateOf(AppUtils.getParamConfig(args))
    }
    val appDataDir = getAppDataDir()
    //日志目录不需要以/结尾, logback.xml文件中会加
    System.setProperty("app.log.dir", "$appDataDir/log")
    val logger = LoggerFactory.getLogger("main")
    logger.debug("进入APP")
    Window(
        onCloseRequest = {
            closeState = UICloseSate.PrepareClose
        },
        title = stringResource(Res.string.app_name),
    ) {
        App(closeState, onConfirmClose = {
            exitApplication()
        }, onCancelClose = {
            closeState = UICloseSate.Idle
        }, paramConfig = paramConfig, onClearParam = {
            paramConfig = ParamConfig()
        })
    }
}